// pages/tabBar/order/index.js
const util = require('../../utils/util')
const app = getApp();
import { billFareCategory, billFareList } from '../../api/billFare'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum:1,
    isChose:0,
    billFareList:[],
    tabCur: 0, //默认选中
    tabs: []

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    billFareCategory().then(res => {
      if(res.data.length > 0){
        this.data.tabCur=0
        this.setData({
          tabs: [{id:0,name:'全部',orders:0},...res.data]
        })
      }
      this.getBillFareList()
    })
  },
  tabSelect(e) {
    this.data.pageNum=1
    this.data.billFareList=[]
    this.setData({
      tabCur: e.currentTarget.dataset.id,
      isChose:e.currentTarget.dataset.index,
      scrollLeft: (e.currentTarget.dataset.id - 2) * 200
    })
    this.getBillFareList()
  },

  getBillFareList() {
    billFareList({ billFareCategoryId: this.data.tabCur||null,pageNum:this.data.pageNum }).then(res => {
      console.log(res)
      res.data.data.forEach(item=>{
        item.love=util.rateConverter(item.love,0)
        item.thumbnail=util.thumbnail(item.thumbnail,190,190)
        this.data.billFareList.push(item)
      })
      console.log(this.data.billFareList)
      this.setData({
        billFareList:  this.data.billFareList
      })
    })
  },
  selectProduct(e) {
    wx.navigateTo({
      url: `./details?id=${e.detail.id}`,
    })
  },
  onReachBottom(){
    this.data.pageNum+=1
  },
})
